package signGrammar.view;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridBagConstraints;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import signGrammar.view.CViewBox.BoxType;

public class CViewProduction extends JPanel {
	private static final long serialVersionUID = -6756801976313850466L;
	
	private static class CViewBoxS extends CViewBox{
		private static final long serialVersionUID = 1L;
		public CViewBoxS(BoxType boxType, Container... things) {
			super(boxType, things);
			setBorder( BorderFactory.createEtchedBorder() );
		}
		protected GridBagConstraints updateConstraints(GridBagConstraints constrs) {
			GridBagConstraints c = super.updateConstraints(constrs);
			c.weightx = 0;
			return c;
		}
	}
	
	public CViewProduction(String nonTerminal, String[] productions) {
		setLayout( new BorderLayout() );
		
		CViewBox bigBox = new CViewBox( BoxType.VERTICAL );
		
		for(int i=0; i<productions.length; i++)
			bigBox.add( new CViewBoxS(BoxType.HORIZONTAL,
				new JLabel( nonTerminal ),
				new JLabel( " -> " ),
				new JLabel( productions[i] )
			));
		
		add( bigBox, "Center" );
	}
}
